package chapter06

/**
 * 特质的叠加
 * 从最后一个开始往前叠加
 */
object Demo15_TraitOverlying {
  def main(array: Array[String]): Unit = {
    val student = new Student15
    student.singing()
    student.dancing()
    student.increase()  //knowledge increase
    println("==================================")

    val myFootBall = new MyFootBall
    println(myFootBall.describe())
  }

}
//定义一个特质
trait Knowledge15{
  var amount: Int = 0
  def increase(): Unit={
    println("knowledge increase")
  }
}
//定义球类
trait Ball{
  def describe(): String = "ball"
}
//定义颜色
trait ColorBall extends Ball{
  var color: String = "red"
  override def describe(): String = color + "_" + super.describe()
}
//定义种类
trait CategoryBall extends Ball{
  var category: String = "foot"
  override def describe(): String = category + "_" + super.describe()
}
//定义一个自定义球
class MyFootBall extends CategoryBall with ColorBall{
  override def describe(): String ="My ball is a" + "_" + super.describe()
}

trait Talent15 {
  def singing(): Unit
  def dancing(): Unit
  def increase(): Unit={
    println("Talent increase")
  }
}
class Student15 extends Person13 with Talent15 with Knowledge15{
  override def singing(): Unit = println("singing")

  override def dancing(): Unit = println("dancing")

  override def increase(): Unit = {
    super.increase()
  }
}